package gui;

import java.awt.EventQueue;
import java.util.Collection;
import java.util.Collections;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JDialog;
import javax.swing.UIManager;

import dao.Dao;

import model.Stack;
import service.LocationNotFoundException;
import service.Service;
import service.StackMonitor;

public class App {
	private static StackMonitor stackMonitor;
	private static MainFrame frame;
	
	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			Service.getInstance().createSomeObjects();
			
			frame = new MainFrame();
			frame.setVisible(true);

			stackMonitor = new StackMonitor(new StackAlert());
			stackMonitor.execute();
		} catch (LocationNotFoundException e) {
			ExceptionHandler.handleException(e);
		} catch (Exception e) {
			ExceptionHandler.handleException(e,
					"Application has failed to start.");
		}

	}

	private static class StackAlert implements Observer {
		@Override
		public void update(Observable o, Object arg) {
			if (arg != null)
				new Notification((Stack) arg);
			else			
				 frame.updateView();
		}
	}
}
